package com.cloud.picture.utils;

import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.cloud.picture.common.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;


/**
 * @author syf
 */
@Slf4j
public class MailUtils {

    @Value("${spring.mail.host}")
    private static String host;

    @Value("${spring.mail.port}")
    private Integer port;

    @Value("${spring.mail.from}")
    private String from;

    @Value("${spring.mail.password}")
    private String password;

    @Value("${spring.mail.username}")
    private String user;

    public BaseResponse<String> sendMail(String email, String code) {
        MailAccount account = new MailAccount();
        account.setHost(host);
        account.setPort(port);
        account.setFrom(from);
        account.setPass(password);
        account.setUser(user);

        String res = MailUtil.send(account, email, "验证码", code, false);
        return ResultUtils.success(res);
    }
}
